﻿#include "OperRenderAttribute.h"
#include "OperatorsInterface/GraphEventOperator.h"

#include "GUIFrame/MainWindow.h"
#include "FITK_Kernel/FITKCore/FITKOperatorRepo.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKRunTimeSetting.h"
#include <QAction>
#include "SARibbonToolButton.h"
namespace ModelOper
{
    bool OperRenderAttribute::execGUI()
    {
        GUI::MainWindow* mw = GUI::MainWindow::GetMainWindowFromFramework();
        if (mw == nullptr) return false;
        QString name = _emitter->objectName();
        if (name.isEmpty()) return false;
        //获取触发当前操作的action
        QAction* action = mw->findChild<QAction*>(name);
        if (action == nullptr) return false;

        bool isEnable = true;
        AppFrame::FITKRunTimeSetting* setting = FITKAPP->getGlobalData()->getRunTimeSetting();
        if (setting == nullptr) return false;
        EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
        if (graphOper == nullptr) return false;
        if (name == "actionPointVisible")
        {
            //设置几何点的显示隐藏状态
            name = "GeoPoint";
            isEnable = setting->getValue(name).toBool();
            graphOper->setPointVisible(!isEnable, false, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visibleGeoPoint.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visibleGeoPoint.png"));
                setting->setValue(name, false);
            }

        }
        if(name == "actionLineVisible")
        {
            //设置几何线的显示隐藏状态
            name = "GeoLine";
            isEnable = setting->getValue(name).toBool();
            graphOper->setLineVisible(!isEnable, false, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visibleGeoLine.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visibleGeoLine.png"));
                setting->setValue(name, false);
            }

        }
        if (name == "actionGeoVisible")
        {
            //设置几何的显示隐藏状态
            name = "Geo";
            isEnable = setting->getValue(name).toBool();
            graphOper->setAllModelVisible(!isEnable, false, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visibleGeo.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visibleGeo.png"));
                setting->setValue(name, false);
            }

        }
        if (name == "actionMeshPointVisible")
        {
            //设置网格点的显示隐藏状态
            name = "MeshPoint";
            isEnable = setting->getValue(name).toBool();
            graphOper->setPointVisible(!isEnable, true, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visibleMeshPoint.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visibleMeshPoint.png"));
                setting->setValue(name, false);
            }
        }
        if (name == "actionMeshLineVisible")
        {
            //设置网格线的显示隐藏状态
            name = "MeshLine";
            isEnable = setting->getValue(name).toBool();
            graphOper->setLineVisible(!isEnable, true, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visibleMeshLine.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visibleMeshLine.png"));
                setting->setValue(name, false);
            }

        }
        if (name == "actionPartVisible")
        {
            //设置Part的显示隐藏状态
            name = "Part";
            isEnable = setting->getValue(name).toBool();
            graphOper->setAllModelVisible(!isEnable, true, false);
            if (!isEnable)
            {
                action->setIcon(QIcon(":/toolBar/visiblePart.png"));
                setting->setValue(name, true);
            }
            else {
                action->setIcon(QIcon(":/toolBar/no_visiblePart.png"));
                setting->setValue(name, false);
            }

        }
        
        //if (!isEnable)
        //{
        //    action->setIcon(QIcon(":/icons/eyesOpen.svg"));
        //    setting->setValue(name, true);
        //}
        //else {
        //    action->setIcon(QIcon(":/icons/eyesClose.svg"));
        //    setting->setValue(name, false);
        //}

        return false;
    }
    bool OperRenderAttribute::execProfession()
    {
        return false;
    }
}
